const parser = require("./parser");

module.exports = async function(data){ 
  let str = data;
  let html = data;
  let reg = RegExp(/\{yx:[a-z]+[\s\S]*?\}([\s\S]*?)\{\/yx:[a-z]+\}/g);
  let arr = [];
  while((arr = reg.exec(str)) != null){ 
    let r = arr[0]; 
    let res = await parserParam(arr);
    html = html.replace(r,res)
  }
  return html;
}

// 解析mod参数 
async function parserParam(arr){ 
  let str = arr[0];
  let reg = RegExp(/(?<=\{yx:)\w*/);
  let mod = reg.exec(str)[0];
  // console.log("mod",mod)
  switch(mod){
    case "header":
      return await parser.header(arr)
    break;
    case "footer":
      return await parser.footer(arr)
    break;
    case "content":
      return parser.content(arr)
    break;
    default:
      return("parser接口错误")
    break;
  }
}